package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.FriendMSGBean;

/**
 * Created by 廉冲-android开发 on 2017/5/17.
 */
public class Friend_Wa_MSGAdapter extends BaseAdapter {
    List<FriendMSGBean.DataEntity.UserbabysEntity> mList = new ArrayList<>();
    LayoutInflater inflater;
    Context context;

    public Friend_Wa_MSGAdapter() {
    }

    public Friend_Wa_MSGAdapter(List<FriendMSGBean.DataEntity.UserbabysEntity> mList, Context context) {
        this.mList = mList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<FriendMSGBean.DataEntity.UserbabysEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_friend_wamsg, null);
            viewHolder = new ViewHolder();

            viewHolder.imageView_friend_wa_headerimg = (SimpleDraweeView) convertView.findViewById(R.id.imageView_friend_wa_headerimg);
            viewHolder.textView_friend_wa_name = (TextView) convertView.findViewById(R.id.textView_friend_wa_name);
            viewHolder.textView_friend_wa_time = (TextView) convertView.findViewById(R.id.textView_friend_wa_time);
            viewHolder.textView_friend_wa_introduce = (TextView) convertView.findViewById(R.id.textView_friend_wa_introduce);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        FriendMSGBean.DataEntity.UserbabysEntity dataEntity = mList.get(position);

        viewHolder.textView_friend_wa_name.setText(dataEntity.getBabyname());
        viewHolder.textView_friend_wa_time.setText(dataEntity.getBabaage());
        viewHolder.textView_friend_wa_introduce.setText(dataEntity.getBabatips());
        viewHolder.imageView_friend_wa_headerimg.setImageURI(Uri.parse(dataEntity.getBabyavatar()));
        return convertView;
    }

    public class ViewHolder {
        SimpleDraweeView imageView_friend_wa_headerimg;
        TextView textView_friend_wa_name;
        TextView textView_friend_wa_time;
        TextView textView_friend_wa_introduce;
    }

}
